package it.trekker.db;

import java.io.Serializable;
import com.google.android.maps.GeoPoint;

import android.location.Location;

public class GPSCoordinate implements Serializable {
	
	private double latitude;
	private double longitude;
	private double altitude;
	
	public GPSCoordinate() {
	}
	
	public GPSCoordinate(Location location) {
		this.latitude = location.getLatitude();
		this.longitude = location.getLongitude();
		this.altitude = location.getAltitude();
	}
	
	public double getLatitude() {
		return latitude;
	}
	
	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}
	
	public double getLongitude() {
		return longitude;
	}
	
	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}
	
	public double getAltitude() {
		return altitude;
	}
	
	public void setAltitude(double altitude) {
		this.altitude = altitude;
	}
	
	public static GeoPoint gpsCoordinate2GeoPoint(GPSCoordinate gpsCoordinate) {
		return gpsCoordinate2GeoPoint(gpsCoordinate.getLatitude(), gpsCoordinate.getLongitude());
	}
	
	public static GeoPoint gpsCoordinate2GeoPoint(double latitude, double longitude) {
		int latE6 = Double.valueOf(latitude * 1E6).intValue();
		int longE6 = Double.valueOf(longitude * 1E6).intValue();
		
		return new GeoPoint(latE6, longE6);
	}
	
	@Override
	public String toString() {
		return String.format("lat: %f - long: %f - alt: %f", latitude, longitude, altitude);
	}
	
	@Override
	public boolean equals(Object o) {
		if(o == null)
			return false;
		if(this == o)
			return true;
		if(!(o instanceof GPSCoordinate))
			return false;
		
		GPSCoordinate other = (GPSCoordinate) o;
		
		if(this.longitude != other.longitude)
			return false;
		if(this.latitude != other.latitude)
			return false;
		if(this.altitude != other.altitude)
			return false;
		
		return true;
	}
}
